import time
from concurrent.futures import ThreadPoolExecutor, as_completed
from tqdm import tqdm


def concurrent_executor(func, args_list, max_workers=2):
    with ThreadPoolExecutor(max_workers) as executor:
        futures = [executor.submit(func, arg) for arg in args_list]
        for future in tqdm(as_completed(futures), total=len(args_list)):
            pass


def inner_task(x):
    time.sleep(1)
    print(f"Inner task {x} done")
    return x


def outer_task(x):
    print(f"Outer task {x} start")
    concurrent_executor(inner_task, [x, x * 10, x * 100])
    print(f"Outer task {x} end")
    return x


# 外层执行
concurrent_executor(outer_task, [1, 2, 3])
